<?php

class Test_Application_Auth extends TestCase {
    
    private $_user;
    
    protected function setUp() {
        parent::setUp();
        $this->_user = $this->_manager->create('BO_User');
        $this->_user->firstName = 'Zenon';
        $this->_user->lastName = 'Boo';
        $this->_user->login = 'zenek';
        $this->_user->password = 'pass';
        $this->_user->email = 'zenek@gmail.com';
    }
    
    protected function tearDown() {
        $this->_manager->delete($this->_user);
        $this->_manager->delete($this->_user2);
        $this->_manager->delete($this->_user3);
        Application_Auth::getInstance()->logout();
    }
    
    public function testAuthenticate() {
        $auth = Application_Auth::getInstance();
        self::assertTrue($auth->authenticate('zenek', 'pass'));
        self::assertFalse($auth->authenticate('zenek', 'passs'));
    }
    
    public function testExists() {
        $auth = Application_Auth::getInstance();
        self::assertTrue($auth->loginExists('zenek'));
    }
    
    public function testCreate() {
        $auth = Application_Auth::getInstance();
        $this->_user2 = $auth->createUser('foo user');
        self::assertEquals(1, count($this->_manager->find('from BO_User where login = ?', 'foo user')));
        try {
            $this->_user3 = $auth->createUser('foo user');
            self::fail('Exception expected');
        } catch (Application_Exception $e) {
            
        }
        
    }

}

?>